package www.openteam.com.presenter.qualityCntrl;

import java.util.HashMap;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.IPQCCheckMan;
import www.openteam.com.bean.IPQCMachine;
import www.openteam.com.bean.IPQCMsg00;
import www.openteam.com.bean.IPQCMsg01;
import www.openteam.com.bean.IPQCProduce;
import www.openteam.com.contract.qualityCntrl.IPQCContract;
import www.openteam.com.model.qualityCntrl.IPQCModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.qualityCntrl.IPQCFragment;

/**
 * Created by OT on 2018-01-09.
 */

public class IPQCPresenter extends BasePresenter<IPQCFragment> implements
        IPQCContract.IPQCPresenter{

    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new IPQCModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> hashMap = new HashMap<>();
        hashMap.put("IPQCPresenter", models[0]);
        return hashMap;
    }

    @Override
    public void findProduce() {
        ((IPQCModel)getiModelMap().get("IPQCPresenter")).findProduce(new IPQCModel.ProduceListener() {
            @Override
            public void success(IPQCProduce ipqcProduce) {
                getIView().findProduce(ipqcProduce);
            }

            @Override
            public void fail(Throwable e) {
                getIView().fail(e.getMessage());
            }
        });
    }

    @Override
    public void findProMachine(String code) {
        ((IPQCModel)getiModelMap().get("IPQCPresenter")).findProMachine(code, new IPQCModel.MachineListener() {
            @Override
            public void success(IPQCMachine ipqcMachine) {
                getIView().findProMachine(ipqcMachine);
            }

            @Override
            public void fail(Throwable e) {
                getIView().fail(e.getMessage());
            }
        });
    }

    @Override
    public void findCheckMan() {
        ((IPQCModel)getiModelMap().get("IPQCPresenter")).findCheckMan(new IPQCModel.CheckManListener() {
            @Override
            public void success(IPQCCheckMan ipqcCheckMan) {
                getIView().findCheckMan(ipqcCheckMan);
            }

            @Override
            public void fail(Throwable e) {
                getIView().fail(e.getMessage());
            }
        });
    }

    @Override
    public void findMsg00(String produce) {
        ((IPQCModel)getiModelMap().get("IPQCPresenter")).findMsg00(produce, new IPQCModel.Msg00Listener() {
            @Override
            public void success(IPQCMsg00 ipqcMsg00) {
                getIView().findMsg00(ipqcMsg00);
            }

            @Override
            public void fail(Throwable e) {
                getIView().fail(e.getMessage());
            }
        });
    }

    @Override
    public void findMsg01(String produce) {
        ((IPQCModel)getiModelMap().get("IPQCPresenter")).findMsg01(produce, new IPQCModel.Msg01Listener() {
            @Override
            public void success(IPQCMsg01 ipqcMsg01) {
                getIView().findMsg01(ipqcMsg01);
            }

            @Override
            public void fail(Throwable e) {
                getIView().fail(e.getMessage());
            }
        });
    }
}
